package com.jiayang.business.homepage;

import com.jiayang.business.homepage.domain.dto.FeedBackDTO;
import com.jiayang.business.homepage.domain.dto.ResponseStationDTO;
import com.jiayang.common.anno.OperateLog;
import com.jiayang.common.domain.ResponseDTO;
import com.jiayang.constant.SwaggerTagConst;
import com.jiayang.base.system.login.domain.RequestTokenBO;
import com.jiayang.util.JYangRequestTokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @ Author     ：OuyangChenglong
 * @ Date       ：Created in 9:56 2021/9/8
 * @ Description：总部首页相关API
 * @ Modified By：
 * @Version: 1.0$
 */
@RestController
@Api(tags = {SwaggerTagConst.Admin.CLIENT_HOME_PAGE})
@OperateLog
public class HomePageController {

    @Autowired
    private HomePageService homePageService;

    @GetMapping("/homepage/initGetStationAndEquipment")
    @ApiOperation(value = "获取所有符合当前登录用户的场站的名字经度纬度和所属设备名", notes = "获取场站地图和设备基础信息 @author OuyangChenglong")
    public ResponseDTO<List<ResponseStationDTO>> initGetStationAndEquipment() {
        RequestTokenBO requestToken = JYangRequestTokenUtil.getRequestUser();
        return homePageService.getStationAndEquipment(requestToken);
    }

    @GetMapping("/homepage/initGetAllEquipmentState")
    @ApiOperation(value = "获取所有符合当前登录用户的所有设备运行情况", notes = "设备运行情况饼状图 @author OuyangChenglong")
    public ResponseDTO initGetAllEquipmentState() {
        RequestTokenBO requestToken = JYangRequestTokenUtil.getRequestUser();
        return homePageService.getAllEquipmentState(requestToken);
    }

    @GetMapping("/homepage/initGetErrorType")
    @ApiOperation(value = "获取所有符合当前登录用户的所有设备故障类型", notes = "故障类型饼状图 @author OuyangChenglong")
    public ResponseDTO initGetErrorType() {
        RequestTokenBO requestToken = JYangRequestTokenUtil.getRequestUser();
        return homePageService.getErrorType(requestToken);
    }

    @GetMapping("/homepage/initGetAllSensorState")
    @ApiOperation(value = "获取所有符合当前登录用户的所有传感器运行情况", notes = "传感器运行情况饼状图 @author OuyangChenglong")
    public ResponseDTO initGetAllSensorState() {
        RequestTokenBO requestToken = JYangRequestTokenUtil.getRequestUser();
        return homePageService.getAllSensorState(requestToken);
    }

    @GetMapping("/homepage/initGetDailyDown")
    @ApiOperation(value = "获取每天停机设备数", notes = "每天停机数统计图 @author OuyangChenglong")
    public ResponseDTO initGetDailyDown() {
        RequestTokenBO requestToken = JYangRequestTokenUtil.getRequestUser();
        return homePageService.getDailyDown(requestToken);
    }

    @GetMapping("/homepage/initGetEnergyConsumption")
    @ApiOperation(value = "获取单日设备能耗", notes = "单日设备耗能统计图 @author OuyangChenglong")
    public ResponseDTO initGetEnergyConsumption() {
        RequestTokenBO requestToken = JYangRequestTokenUtil.getRequestUser();
        return homePageService.getEnergyConsumption(requestToken);
    }

    @GetMapping("/homepage/initGetDailyAlarm")
    @ApiOperation(value = "获取单日报警数", notes = "单日报警数统计图 @author OuyangChenglong")
    public ResponseDTO initGetDailyAlarm() {
        RequestTokenBO requestToken = JYangRequestTokenUtil.getRequestUser();
        return homePageService.getDailyAlarm(requestToken);
    }

    @GetMapping("/homepage/initGetOnlineEquipment")
    @ApiOperation(value = "获取设备在线运行率", notes = "设备在线运行率统计图 @author OuyangChenglong")
    public ResponseDTO initGetOnlineEquipment() {
        RequestTokenBO requestToken = JYangRequestTokenUtil.getRequestUser();
        return homePageService.getOnlineEquipment(requestToken);
    }

    @GetMapping("/homepage/initGetOnlineSensor")
    @ApiOperation(value = "获取传感器在线率", notes = "传感器在线率统计图 @author OuyangChenglong")
    public ResponseDTO initGetOnlineSensor() {
        RequestTokenBO requestToken = JYangRequestTokenUtil.getRequestUser();
        return homePageService.getOnlineSensor(requestToken);
    }

    @GetMapping("/homepage/initGetTopFive")
    @ApiOperation(value = "获取top5故障累计", notes = "top5故障统计图 @author OuyangChenglong")
    public ResponseDTO initGetTopFive() {
        RequestTokenBO requestToken = JYangRequestTokenUtil.getRequestUser();
        return homePageService.getTopFive(requestToken);
    }

    @GetMapping("/homepage/initGetInfo")
    @ApiOperation(value = "获取软件信息", notes = "版本信息按钮事件 @author OuyangChenglong")
    public ResponseDTO initGetInfo() {
        RequestTokenBO requestToken = JYangRequestTokenUtil.getRequestUser();
        return homePageService.getInfo(requestToken);
    }

    @PostMapping("/homepage/feedback")
    @ApiOperation(value = "接收用户反馈", notes = "版本信息信息中用户点击提交反馈的事件 @author OuyangChenglong")
    public ResponseDTO updateFeedBack(@RequestBody @Valid FeedBackDTO feedbackDto) {
        RequestTokenBO requestToken = JYangRequestTokenUtil.getRequestUser();
        return homePageService.updateFeedBack(feedbackDto,requestToken);
    }
}
